<template>
	<view class="page-wrap">
		<view class="title">账号密码登录</view>
		<view class="title-dec">每天，进步一点点</view>
		<view class="content">
			<view class="input-box">
				<input type="text" v-model="form.username" placeholder="请输入手机号" class="common-input">
				<input type="password" v-model="form.password" placeholder="请输入密码" class="common-input">
				<view class="btn" @tap="submit">登录</view>
			</view>
			<image class="logo" src="/static/logo.png"></image>
		</view>
	</view>
</template>

<script>
import { login, getOpenId } from "@/api/login"
// import { getUserInfo } from '@/utils/utils'
// import config from '@/utils/config'
export default {
	data() {
		return {
			form: {
				username: '',
				password: '',
				// openid: 'dfsdf',
				openid:''
			}
		}
	},
	onLoad() {
		console.log('login--->', wx.getAppBaseInfo().SDKVersion)
		wx.login({
			success: res => {
				console.log('code--->',res.code)
				getOpenId({
					code: res.code
				}).then(res => {
					console.log('openid--->', res.openid)
					this.form.openid = res.openid

					// 设置openid 
					uni.setStorageSync('openid',res.openid)
				})
			}
		})
	},
	methods: {
		async submit() {
			// if (!(/^1[3456789]\d{9}$/.test(this.form.phone))) {
			// 	return wx.showToast({
			// 		title: '请输入正确手机号',
			// 		icon: 'none'
			// 	});
			// }
			// if (this.form.password.length < 6) {
			// 	return wx.showToast({
			// 		title: '密码至少为6位数',
			// 		icon: 'none'
			// 	});
			// }

			let res=await login(this.form)
			wx.setStorageSync('token',res.token)
			wx.setStorageSync('userInfo',res)
            setTimeout(()=>{
				wx.navigateTo({
				url: '/pages/index/index'
			   })
			})
		}
	}
}
</script>

<style src="./assets/index.scss" lang="scss" scoped></style>


